function AJAX(method, url, data, FN) {
	$.ajax({
		type: method,
		url: url,
		data: data,
		xhrFields: {
			withCredentials: true
		},
		success: function (result) {
			FN(result);
		},
		error: function () {
		},
		complete: function () {
		}
	})
}
// var Base = "http://192.168.1.9:3008/";
var Base = "http://114.55.254.244:80/";
var Burl = {
	check: Base + "check",
	logout: Base + "logout",
	register: Base + "register",
	detail: Base + "vote/detail",
	login: Base + "login",
	add: Base + "comment/add",
	update: Base + "comment/update",
	list: Base + "comment/list",
	vote_list: Base + "vote/list",
	vote_add: Base + "vote/add",
	comment_delete: Base + "comment/delete",
	create: Base + "vote/create"

}

function BOX(color, content) {
	new jBox('Notice', {
		animation: 'flip',
		color: color,
		content: content,
		delayOnHover: true,
		showCountdown: true
	});
}
function Gettime(date) {
	var Odate = new Date(date)
	return Odate.getFullYear() + "-" + (Odate.getMonth() + 1) + '-' + Odate.getDate() + " " + Odate.getHours() + ":" + Odate.getMinutes() + ":" + Odate.getSeconds()
}

function logout(url) {
	var Too = $("<div></div>")
	var T1 = $("<div class='UI'></div>").text("签到")
	var T2 = $("<div class='UI'></div>").text("注销")
	var T3 = $("<div class='UI'></div>").text("留言板")
	var T4 = $("<div class='UI'></div>").text("创建投票")
	Too.append(T1)
	Too.append(T2)
	Too.append(T3)
	Too.append(T4)
	new jBox('Tooltip', {
		attach: ".Too",
		width: 200,
		closeOnMouseleave: true,
		animation: 'zoomIn',
		content: Too
	});
	//注销请求
	T2.on("click", function () {
		AJAX("GET", Burl.logout, null, function (result) {
			if (result.status == true) {
				window.location.href = url
			}
		})
	})
	T3.on("click", function () {
		window.location.href = "./comment.html"
	})
	T4.on("click", function () {
		window.location.href = "./create.html"
	})
}
function inde() {
	$(".name").on("click", function () {
		if ($(".name")[0].innerText == "游客") {
			window.location.href = "./login.html"
		}
	})
}
function check(FN, FN1) {
	AJAX("GET", Burl.check, null, function (result) {
		//成功执行
		if (result.status == true) {
			FN(result)
		} else if (result.status == false) {//不成功执行
			BOX("red", "注销成功，点击游客登录")
			inde();
		}
	})
}


